<template>
	<div>
		<Select v-model="selectValue" 
    		filterable 
            :remote-method="queryChange"
            :loading="loading"
            style="width:300px" >
                <Option v-for="item in selectData" :value="item.value" :key="item.value">{{ item.label }}</Option>
            </Select>
    </div>
</template>

<script>
import Ajax from "../../js/Ajax/index.js"
import axios from 'axios'

Ajax.init({
		baseUrl: "", // 是否设置 http(s)://***.com/, 即 http_origin，默认为空
		apiList: {}, // http请求地址的字典型
		checkToken: true // 是否在每个请求的头部设置token，默认为true
	});
	var STAFF_URL;

	if(window.F2ESDK_CONFIG && window.F2ESDK_CONFIG.apiServer && window.F2ESDK_CONFIG.apiServer.STAFF_URL) {
		STAFF_URL = window.F2ESDK_CONFIG.apiServer.STAFF_URL;
	}

	const THIS_URL = STAFF_URL || "http://192.168.10.202:4444/gateway/api-ms/system/posts";
	var getData = Ajax.methods;;

export default {
	props: {
			// 创建时的默认值
			defaultValue: {
				type: String
			},
			// 创建时的默认值
			disabledIds: {
				type: Object,
				default: function() {
					return {
						'123456': false
					}
				}
			},
			//传入key值
			basicKey: {
				type: String
			},
			// 用户自定义URL
			basicUrl: {
				type: String
			},
			// 是否支持搜索
			filterable: {
				type: Boolean,
				default: false
			},
			// 是否禁用
			disabled: {
				type: Boolean,
				default: false
			},
			// 未输入时显示的提示
			placeholder: {
				default: '请选择'
			},
			// 下拉框展开方向
			placement: {
				type: String,
				default: 'bottom'
			}
		},
    name: 'selectDriver',
    data: function() {
		return {
			driverList: [],
			selectData:[],
			selectValue: null,
	        sc:'',//选中事件
	        qc:'',//查询事件
	        bl:'',//加载前
	        oe:'',//加载失败
	        os:'',//加载成功
        	loading: false,
		}
    },
    methods: {
				//选中事件
	      selectChange: function(val){
	        var that = this;
	        that.sc = "value:" + val.value + " label:" + val.label;
	      },
	      //框内输入值
	      queryChange: function(query){
	        var that = this;
	        that.qc = query;
	        console.log(that.qc)
	        
	    	var searchFiltersJson={};
	    	var filters={};
	    	var rules=[];
	    	var data1={};
	    	data1.field='active';
	    	data1.op='eq';
	    	data1.data='0';
	    	rules.push(data1);
	    	
	    	if (query.length > 0) {
		    	var datas={};
		    	datas.field='carrierName';
		    	datas.op='cn';
		    	datas.data=query;
		    	rules.push(datas);
	    	}
	    	
	    	filters.groupOp='and';
	    	filters.rules=rules;
	    	searchFiltersJson.filters=filters;
    	
    		that.loading = true;
				getData.get('users', {
					params: {
						page: 1,
						rows: 10,
						data: searchFiltersJson
					}
			}).then(function(res) {
          		that.driverList=res.data.data;
			});
	      },
	      // 加载成功回调函数
	      onLoadSuccess: function(data){
	        var that = this;
	        that.os = data.toString();
	      },
	      // 加载失败，返回错误信息
	      onError: function(v){
	        var that = this;
	        that.oe = v;
	      },
	      // 加载前回调函数
	      beforeLoad: function(){
	        var that = this;
	        that.bl = '加载前干的事';
	      },
	      //获取数据
			getData: function() {
				var that = this;
				var url;
				console.log("that.basicUrl",that.basicUrl)
				if(that.basicUrl == "") { //没有自定义url
					url = THIS_URL
				} else { //自定义url
					url = "http://192.168.10.202:4444/gateway/api-ms/system/" + that.basicUrl;
				}
				getData.getUrl("http://192.168.10.202:4444/gateway/api-ms/system/posts").then(function(res) {
					if(res.data.resultCode == 0) {
						console.log(res.data.data)
						for(var i = 0; i < res.data.data.length; i++) {
							that.selectData.push({
								value:res.data.data[i].postId,
                				label:res.data.data[i].postName
							});
						}
					} else {
						that.onError(res.data.resultMsg);
					}
				});
			}
		},
    	mounted: function(){
    		var that = this;
			that.getData();
    }
}
</script>